package P1000;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author: zhouyang
 * @descrpition:
 * @time: 2019-10-08 14:12
 */
public class P1427_小鱼的数字游戏 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Stack<Integer> stack = new Stack<>();
        while(true){
            int now = scanner.nextInt();
            if(now != 0){
                stack.add(now);
            }else{
                scanner.close();
                break;
            }
        }
        if(!stack.isEmpty()){
            System.out.printf("%d",stack.pop());
        }
        while(!stack.isEmpty()){
            System.out.printf(" %d",stack.pop());
        }
    }
}
